<h1>Offers List</h1>

<a href="<?php echo url_for('offer/new') ?>">New</a>

<div class="pager clearfix">
  <?php if ($pager->haveToPaginate()): ?>
    <?php echo link_to('&laquo;', 'offer/index?page='.$pager->getFirstPage().($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
    <?php echo link_to('&lt;', 'offer/index?page='.$pager->getPreviousPage().($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
    <?php $links = $pager->getLinks(); foreach ($links as $page): ?>
      <?php echo ($page == $pager->getPage()) ? link_to($page, 'offer/index?page='.$page.($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):''), array('class' => 'selected')) : link_to($page, 'offer/index?page='.$page.($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
    <?php endforeach ?>
    <?php echo link_to('&gt;', 'offer/index?page='.$pager->getNextPage().($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
    <?php echo link_to('&raquo;', 'offer/index?page='.$pager->getLastPage().($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
  <?php endif ?>
</div>

<table class="admin">
  <thead>
    <tr>
      <th>Id</th>
      <th>Site</th>
      <th>Name</th>
      <th>Discount percent</th>
      <th>City</th>
      <th>Start time</th>
      <th>End time</th>
      <th>Created at</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($pager->getResults() as $Offer): ?>
    <tr <?php if($Offer->isActive()): ?>class="active<?php if(!$Offer->getOnSite()): ?> offline<?php endif; ?>"<?php endif; ?>>
      <td><a href="<?php echo url_for('offer/edit?id='.$Offer->getId()) ?>"><?php echo $Offer->getId() ?></a></td>
      <td><?php echo $Offer->getSite() ?></td>
      <td><a href="<?php echo url_for($Offer->getRouteName().'?id='.$Offer->getId()) ?>"><?php echo $Offer->getName() ?></a></td>
      <td><?php echo $Offer->getDiscountPercent() ?></td>
      <td><?php echo $Offer->getCitiesString() ?></td>
      <td><?php echo $Offer->getStartTime() ?></td>
      <td><?php echo $Offer->getEndTime() ?></td>
      <td><?php echo $Offer->getCreatedAt() ?></td>
      <td>
        <?php if($Offer->getOnSite()): ?>
          <a href="<?php echo url_for('offer/onsite?value=0&id='.$Offer->getId()) ?>">Put offline</a>
        <?php else: ?>
          <a href="<?php echo url_for('offer/onsite?value=1&id='.$Offer->getId()) ?>">Put online</a>
        <?php endif; ?>
        <br />
        <?php echo link_to('Delete', 'offer/delete?id='.$Offer->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
      </td>
    </tr>
    <?php endforeach; ?>
  </tbody>
</table>

<div class="pager clearfix">
  <?php if ($pager->haveToPaginate()): ?>
    <?php echo link_to('&laquo;', 'offer/index?page='.$pager->getFirstPage().($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
    <?php echo link_to('&lt;', 'offer/index?page='.$pager->getPreviousPage().($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
    <?php $links = $pager->getLinks(); foreach ($links as $page): ?>
      <?php echo ($page == $pager->getPage()) ? link_to($page, 'offer/index?page='.$page.($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):''), array('class' => 'selected')) : link_to($page, 'offer/index?page='.$page.($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
    <?php endforeach ?>
    <?php echo link_to('&gt;', 'offer/index?page='.$pager->getNextPage().($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
    <?php echo link_to('&raquo;', 'offer/index?page='.$pager->getLastPage().($sf_request->getParameter('site_id')?'&site_id='.$sf_request->getParameter('site_id'):'').($sf_request->getParameter('date')?'&date='.$sf_request->getParameter('date'):'')) ?>
  <?php endif ?>
</div>

<a href="<?php echo url_for('offer/new') ?>">New</a>
